package tpdisenio2009.mvp.display;

import java.util.List;
import javax.swing.table.AbstractTableModel;
import tpdisenio2009.model.beans.SoccerMatch;
import tpdisenio2009.model.beans.SoccerPlayer;

/**
 *
 * @author Nicolás Kreiff
 */
public class SoccerPlayerTableModel extends AbstractTableModel {

    private final List<SoccerPlayer> players;

    public SoccerPlayerTableModel(List<SoccerPlayer> players) {
        this.players = players;
    }

    public SoccerPlayer getSoccerPlayer(int row) {
        if (row < 0 || row >= players.size())
            return null;
        return players.get(row);
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0: return "Puesto";
            case 1: return "Jugador";
            case 2: return "Camiseta";
            default: return "";
        }
    }

    public int getRowCount() {
        return players.size();
    }

    public int getColumnCount() {
        return 3;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        try {
            SoccerPlayer player = this.players.get(rowIndex);
            switch (columnIndex) {
                case 0:
                    return player.getPosition();
                case 1:
                    return player.getLastName() + ", " + player.getFirstName();
                case 2:
                    return player.getShirtNumber();
            }
        } catch (Exception e) {
        }
        return null;
    }
}
